﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using Water.Web.Controls.BaseInterface;
using Water.Web.Controls.Attribute;

namespace Water.Web.Controls
{
    public partial class Menu
    {
        private bool packageDisplay = true;

        [Browsable(true), Category("Appearance"), GlobalizeDescription("PackageDisplay"),DefaultValue(true)]
        public bool PackageDisplay
        {
            get { return packageDisplay; }
            set { packageDisplay = value; }
        }
        private string packageCssClass = "hMenu_package hMenu_package_bg";

        [Browsable(true), Category("Appearance"), GlobalizeDescription("PackageCssClass"), DefaultValue("hMenu_package hMenu_package_bg")]
        public string PackageCssClass
        {
            get { return packageCssClass; }
            set { packageCssClass = value; }
        }

        private Style packageStyle;

        [Browsable(true),PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true), WebCategory("Styles"),  DefaultValue((string)null)]
        public Style PackageStyle
        {
           get
            {
                if (this.packageStyle == null)
                {
                    this.packageStyle = new MenuItemStyle();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager) this.packageStyle).TrackViewState();
                    }
                }
                return this.packageStyle;
            }
        }
        protected virtual void AddRenderPackageAttribute(HtmlTextWriter write)
        {
            if (this.packageStyle!=null)
              this.packageStyle.AddAttributesToRender(write);
            
            if(!this.PackageDisplay)
              write.AddStyleAttribute(HtmlTextWriterStyle.Display, "none");
        }

        protected override void OnPreRender(EventArgs e)
        {
            if (this.PackageStyle != null)
            {
                if (this.Orientation == Orientation.Horizontal)
                {
                    if (string.IsNullOrEmpty(this.packageStyle.CssClass))
                        this.packageStyle.CssClass = "hMenu_package hMenu_package_bg";
                    if (string.IsNullOrEmpty(this.StaticMenuItemStyle.CssClass))
                        this.StaticMenuItemStyle.CssClass = "hStaticMenuItem";
                }
                else
                {
                    if (string.IsNullOrEmpty(this.packageStyle.CssClass))
                        this.packageStyle.CssClass = "vMenu_package vMenu_package_bg";
                    if (string.IsNullOrEmpty(this.StaticMenuItemStyle.CssClass))
                        this.StaticMenuItemStyle.CssClass = "vStaticMenuItem";
                }

            }

            if (string.IsNullOrEmpty(this.StaticHoverStyle.CssClass))
                this.StaticHoverStyle.CssClass = "staticHover";
            if (string.IsNullOrEmpty(this.DynamicMenuStyle.CssClass))
                this.DynamicMenuStyle.CssClass = "dynamicMenu";
            if (string.IsNullOrEmpty(this.DynamicMenuItemStyle.CssClass))
                this.DynamicMenuItemStyle.CssClass = "dynamicMenuItem";
            if (string.IsNullOrEmpty(this.DynamicHoverStyle.CssClass))
                this.DynamicHoverStyle.CssClass = "dynamicHover";
            if (this.DynamicHorizontalOffset == 0)
                this.DynamicHorizontalOffset = 3;
            if (this.DynamicVerticalOffset == 0)
                this.DynamicVerticalOffset = 2;
            base.OnPreRender(e);
        }
        /*
        protected override void OnInit(EventArgs e)
        {
            if (this.PackageStyle != null)
            {
                if (this.Orientation == Orientation.Horizontal)
                {
                    if (string.IsNullOrEmpty(this.packageStyle.CssClass))
                        this.packageStyle.CssClass = "hMenu_package hMenu_package_bg";
                    if (string.IsNullOrEmpty(this.StaticMenuItemStyle.CssClass))
                        this.StaticMenuItemStyle.CssClass = "hStaticMenuItem";
                }
                else 
                {
                    if (string.IsNullOrEmpty(this.packageStyle.CssClass))
                        this.packageStyle.CssClass = "vMenu_package vMenu_package_bg";
                    if (string.IsNullOrEmpty(this.StaticMenuItemStyle.CssClass))
                        this.StaticMenuItemStyle.CssClass = "vStaticMenuItem";
                }

            }

            if (string.IsNullOrEmpty(this.StaticHoverStyle.CssClass))
                this.StaticHoverStyle.CssClass = "staticHover";
            if (string.IsNullOrEmpty(this.DynamicMenuStyle.CssClass))
                this.DynamicMenuStyle.CssClass = "dynamicMenu";
            if (string.IsNullOrEmpty(this.DynamicMenuItemStyle.CssClass))
                this.DynamicMenuItemStyle.CssClass = "dynamicMenuItem";
            if (string.IsNullOrEmpty(this.DynamicHoverStyle.CssClass))
                this.DynamicHoverStyle.CssClass = "dynamicHover";
            if (this.DynamicHorizontalOffset == 0)
                this.DynamicHorizontalOffset = 3;
            if (this.DynamicVerticalOffset == 0)
                this.DynamicVerticalOffset = 2;
            base.OnInit(e);
        }
         */
    }
}
